package com.fc.test.api;

import com.fc.test.model.auto.TAbbGoods;
import com.fc.test.model.auto.TAbbKefu;
import com.fc.test.model.auto.TAbbPinglun;
import com.fc.test.model.auto.TAbbRenzheng;
import com.fc.test.service.TAbbGoodsService;
import com.fc.test.service.TAbbPinglunService;
import com.fc.test.service.TAbbRenzhengService;
import com.fc.test.util.JsonUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "apiGoodsController")
@Api(value = "商品")
public class ApiGoodsController {

    @Autowired
    private TAbbGoodsService goodsService;

    @Autowired
    private TAbbPinglunService pinglunService;

    @Autowired
    private TAbbRenzhengService renzhengService;

    @ResponseBody
    @PostMapping(value = "/getCuxiaoBannerList",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "同城促销页面banner")
    public String getCuxiaoBannerList(){
        Map<String,Object> resMap = new HashMap<>();
        List<TAbbGoods> list = goodsService.getCuxiaoBannerList();
        if(list.size()>0){
            resMap.put("msg","获取促销页面banner成功");
        }else{
            resMap.put("msg","后台未上传热推产品");
        }
        resMap.put("success",true);
        resMap.put("list",list);
        return JsonUtil.jsonMapStr(resMap);
    }


    @ResponseBody
    @PostMapping(value = "/getCuxiaoGoodsList",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "同城促销根据分类查询商品列表")
    public String getCuxiaoGoodsList(
            @ApiParam(value = "分类名称") @RequestParam(value = "area") String area,
            @ApiParam(value = "页码") @RequestParam(value = "page") int page
    ){
        Map<String,Object> resMap = new HashMap<>();
        List<TAbbGoods> list = goodsService.getCuxiaoGoodsList(area,page);
        if(list.size()>0){
            resMap.put("msg","获取促销商品列表成功");
        }else{
            resMap.put("msg","到底了");
        }
        resMap.put("success",true);
        resMap.put("list",list);
        return JsonUtil.jsonMapStr(resMap);
    }

    @ResponseBody
    @PostMapping(value = "/getGoodsDetail",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "商品详情")
    public String getGoodsDetail(
            @ApiParam(value = "商品id") @RequestParam(value = "goodsid") String goodsid
    ){
        Map<String,Object> resMap = new HashMap<>();
        TAbbGoods goods = goodsService.selectByPrimaryKey(goodsid);
        if(null!=goods.getType()&&1==goods.getType()){
            String shopId = goods.getShopid();
            TAbbRenzheng renzheng = renzhengService.selectByPrimaryKey(shopId);
            resMap.put("shopInfo",renzheng);
        }
        resMap.put("success",true);
        resMap.put("msg","获取商品详情成功");
        resMap.put("data",goods);
        return JsonUtil.jsonMapStr(resMap);
    }

    @ResponseBody
    @PostMapping(value = "/getHuigouGoodsPinglun",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "大商惠购商品详情页评论")
    public String getHuigouGoodsPinglun(
            @ApiParam(value = "商品id") @RequestParam(value = "goodsid") String goodsid,
            @ApiParam(value = "页码") @RequestParam(value = "page") int page
    ){
        Map<String,Object> resMap = new HashMap<>();
        List<TAbbPinglun> list = pinglunService.getHuigouGoodsPinglun(goodsid,page);
        resMap.put("success",true);
        resMap.put("msg","获取商品评论成功");
        resMap.put("list",list);
        return JsonUtil.jsonMapStr(resMap);
    }

    @ResponseBody
    @PostMapping(value = "/searchHuigouGoodsList",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "大商惠购搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name="kinds",value = "分类名称",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name="address",value = "地址定位",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name="condition",value = "搜索条件",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer",paramType = "query")
    })
    public String searchHuigouGoodsList(String kinds,String address,String condition, int page){
        Map<String,Object> resMap = new HashMap<>();
        List<TAbbGoods> list = goodsService.searchHuigouGoodsList(kinds,address,condition,page);
        if(list.size()>0){
            resMap.put("success",true);
            resMap.put("msg","获取搜索结果成功");
            resMap.put("list",list);
        }else{
            resMap.put("success",true);
            resMap.put("msg","到底了");
            resMap.put("list",list);
        }
        return JsonUtil.jsonMapStr(resMap);
    }


    @ResponseBody
    @PostMapping(value = "/getQianggouGoodsList",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "抢购商品专区")
    public String getQianggouGoodsList(
            @ApiParam(value = "定位区县") @RequestParam(value = "address") String address,
            @ApiParam(value = "页码") @RequestParam(value = "page") int page
    ){
        Map<String,Object> resMap = new HashMap();
        List<TAbbGoods> list = goodsService.getQianggouGoodsList(address,page);
        if(list.size()>0){
            resMap.put("msg","获取抢购商品成功");
        }else{
            resMap.put("msg","到底了");
        }
        resMap.put("success",true);
        resMap.put("list",list);
        return JsonUtil.jsonMapStr(resMap);
    }

    @ResponseBody
    @PostMapping(value = "/getMeishiGoodsList",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "大商惠购美食专区")
    public String getMeishiGoodsList(
            @ApiParam(value = "定位区县") @RequestParam(value = "address") String address,
            @ApiParam(value = "页码") @RequestParam(value = "page") int page
    ){
        Map<String,Object> resMap = new HashMap();
        List<TAbbGoods> list = goodsService.getMeishiGoodsList(address,page);
        if(list.size()>0){
            resMap.put("msg","获取美食专区商品成功");
        }else{
            resMap.put("msg","到底了");
        }
        resMap.put("success",true);
        resMap.put("list",list);
        return JsonUtil.jsonMapStr(resMap);
    }


    @ResponseBody
    @PostMapping(value = "/getShopList",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "分类查询店铺列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="kinds",value = "分类名称",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name="address",value = "定位地址",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer",paramType = "query")
    })
    public String getShopList(String kinds,String address,int page){
        Map<String,Object> resMap = new HashMap<>();
        List<TAbbRenzheng> list = goodsService.getShopList(kinds,address,page);
        if(list.size()>0){
            resMap.put("success",true);
            resMap.put("msg","获取店铺列表成功");
            resMap.put("list",list);
        }else{
            resMap.put("success",true);
            resMap.put("msg","到底了");
            resMap.put("list",list);
        }
        return JsonUtil.jsonMapStr(resMap);
    }

    @ResponseBody
    @PostMapping(value = "/getHuigouGoodsByShopId",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据商铺id查询商品列表")
    public String getHuigouGoodsByShopId(
            @ApiParam(value = "页码") @RequestParam(value = "page") int page,
            @ApiParam(value = "商铺id") @RequestParam(value = "shopid") String shopid
    ){
        Map<String,Object> resMap = new HashMap<>();
        List<TAbbGoods> list = goodsService.getHuigouGoodsByShopId(shopid,page);
        TAbbRenzheng renzheng = renzhengService.getRenzhengStatus(shopid);
        if(list.size()>0){
            resMap.put("msg","获取商品列表成功");
        }else{
            resMap.put("msg","到底了");
        }
        resMap.put("success",true);
        resMap.put("list",list);
        resMap.put("shopInfo",renzheng);
        return JsonUtil.jsonMapStr(resMap);
    }


    @ResponseBody
    @PostMapping(value = "/getRecommendGoods",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "同城促销/大商惠购推荐商品弹窗")
    public String getRecommendGoods(
            @ApiParam(value = "1大商惠购;2同城促销") @RequestParam(value = "type") int type
    ){
        Map<String,Object> resMap = new HashMap<>();
        resMap = goodsService.getRecommendGoods(type);
        return JsonUtil.jsonMapStr(resMap);
    }

}
